首发 | 您所在的位置:网站首页 › shairport-sync 蓝牙 › 首发 |
目前市场上有专业的多房间有线无线音箱同步方案,费用不菲。本文的目标是低成本,组建低误差的多房间无线音箱。本方案不仅支持安卓音箱(小米/R1),也支持Openwrt音箱,也支持通过树莓派/盒子+有线音箱,也支持Windows,MacOS等。 ## 同步多个音箱方案(苹果生态) Homepod/HomePodMini方案。 其它商业方案,如Sonos等。 苹果Airport-Express,A1392型号,插上3.5口音频线,苹果本身最便宜等方案了。 使用 OwnTone (以前叫 forked-daapd),支持 AirPlay devices/speakers, Apple Remote (and compatibles), MPD clients, Chromecast, network streaming, internet radio, Spotify and LastFM. 此方案Up主也用过,次方案最大的问题是多个音箱无法同步,影响听感。 本文方案,安装Snapcast+SnapClient。 Snapcast 是一个多房间客户端-服务器音频播放器,所有客户端都与服务器时间同步以播放完美同步的音频。它不是一个独立的播放器,而是一个扩展,可以将您现有的音频播放器变成类似 Sonos 的多房间解决方案。音频由服务器捕获并路由到连接的客户端。多个播放器可以并行地向服务器提供音频,并且可以将客户端分组以播放相同的音频流。使用 Snapcast 的最通用方法之一是与音乐播放器守护程序 ( MPD ) 或Mopidy结合使用。Link The Snapserver reads PCM chunks from configurable stream sources: Named pipe, e.g. /tmp/snapfifo ALSA to capture line-in, microphone, alsa-loop (to capture audio from other players) TCP stdout of a process Many more Client介绍客户端将使用系统的低级音频API作为音频后端,以获得最好的控制和最精准的时间,以实现完美同步播放。 使用命令行参数配置可用的音频后端--player 控制端服务器自带Snapweb,这个WebApp可以在下找到http://:1780。 Snapcast 可以通过纯 TCP、HTTP 或 Websockets 使用JSON-RPC API进行控制 安卓客户端在Snapdroid 硬件需求安装Linux的机器,最便宜的N1等Arm盒子,X86服务器,群晖等安装Snapserver。 音箱,以下任意 安卓音箱,需要可以安装APK,例如FX的R1音箱,小米等 Openwrt音箱,例如小米AI音箱(一代黑板),也有以前的一些便宜的路由器。 树莓派/盒子(如N1/HK1Box/移动盒子)+有线音箱,如没有音频输出口的需要加一个USB-DAC。 电脑/开发版,SnapClient支持浏览器输出。 软件需求Linux系统,这里使用安装有Debian系统的N1. Snapcast ,Snapclient 音箱设备安装Snapclient,这里使用R1音箱安装Snapdroid 苹果Airplay2 需要安装 shairport-sync 安卓设备投射,可选 例如dlna renderer HomeAssistant 控制,可选 HomeAssistant 在线音乐 ha_cloud_music ,可选 安装过程打开安装好Armbian的N1,SSH客户端连接N1,下载Snapcast源码,编译安装(也可以直接安装deb包)。
详细安装Snapcast过程见官方文档 https://github.com/badaix/snapcast/blob/v0.26.0/doc/install.md#debian https://github.com/badaix/snapcast/blob/master/doc/build.md#linux-native 安装shairport-sync过程 $ git clone https://github.com/mikebrady/shairport-sync.git $ cd shairport-sync $ autoreconf -fi $ ./configure --sysconfdir=/etc --with-alsa \ --with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-airplay-2 $ make $ make install 详细见官方文档 注意这里使用如下编译参数 ./configure --sysconfdir=/etc --with-alsa --with-stdout--with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-airplay-2 --with-mqtt-client --with-pipe --with-metadata --with-apple-alac --with-soxr 安装 NQPTP Skip this section if you are building classic Shairport Sync – NQPTP is not needed for classic Shairport Sync.Download, install, enable and start NQPTP from here.https://github.com/mikebrady/nqptp $ git clone https://github.com/mikebrady/nqptp.git$ cd nqptp$ autoreconf -fi$ ./configure --with-systemd-startup$ make$ make install# systemctl enable nqptp# systemctl start nqptp安装MQTT 控制包 MQTT in Shairport Sync https://github.com/mikebrady/shairport-sync/blob/master/MQTT.mdTo enable Shairport Sync to act as an MQTT publisher, you need to: Install the mosquitto library:apt install libmosquitto-dev shairport配置文件 /etc/shairport-sync.conf`general = {name = "全屋音频";output_backend = "stdout";port = 5200; #7000airplay_device_id_offset = 0;alac_decoder = "apple";}; metadata ={enabled = "yes";include_cover_art = "yes";cover_art_cache_directory = "/tmp/shairport-sync/.cache/coverart-snap";pipe_name = "/tmp/shairport-sync-metadata-snap";pipe_timeout = 5000; }; mqtt ={enabled = "yes";hostname = "192.168.1.xx";port = 1883;username = "mqtt";password = "xxx";topic = "player/shairport";publish_parsed = "yes";empty_payload_substitute = "--";publish_cover = "yes";enable_remote = "yes";}; sessioncontrol ={active_state_timeout = 30.0;allow_session_interruption = "yes";session_timeout = 120;};` SnapServer配置文件:/etc/snapserver.conf`[server]threads = 4[http]enabled = truebind_to_address = 0.0.0.0port = 1780doc_root = /usr/share/snapserver/snapweb/ [tcp]enabled = truebind_to_address = 0.0.0.0port = 1705[stream]bind_to_address = 0.0.0.0port = 1704 source = airplay:///shairport-sync?name=Airplay&devicename=全屋音频&port=5200&output_backend=stdout#source = pipe:///tmp/snapfifo?name=mopidy&mode=read#name=mopidy&sampleformat=48000:16:2&codec=flac&mode=read codec = pcm#codec = flacbuffer = 500send_to_muted = false[logging] `3. R1安装APK,下载地址 https://github.com/badaix/snapdroid/releases/tag/v0.26.0 1.连接设备 adb connect ip:5555 2.上传安装包 adb push Snapcast_0.26.0.apk /data/local/tmp/ 3. 打开允许安装未知软件 adb shell settings put secure install_non_market_apps 1 adb shell settings get secure install_non_market_apps (该命令返回数字1,即开启成功)) 4. 安装软件 adb shell /system/bin/pm install -t /data/local/tmp/Snapcast_0.26.0.apk 出现success安装成功 5. 使用Scrcpy启动软件,配置Snapcast scrcpy --tcpip=192.168.1.65具体过程请参照网络文章,例如。 注意事项1. shairport-sync 不需要手动启动,由Snapserver自动启动。2. Mqtt配置非必选3. 更多说明,请参照官方文档。4. 以下步骤,等待下一个视频。 * * *- 5. 安卓设备投射,可选 例如dlna renderer * * *- 6. HomeAssistant 控制,可选 * * *- 7. HomeAssistant 在线音乐 ha_cloud_music ,可选 参考: https://github.com/badaix/snapcast https://github.com/mikebrady/shairport-sync https://github.com/shaonianzhentan/ha_cloud_music |
CopyRight 2018-2019 实验室设备网 版权所有 |